package com.merry.jedis.demo;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

import java.util.List;

public class LettuceDemo {
    public static void main(String[] args) {
        //1.使用构建器链式编程来builder我们redis URI
        RedisURI redisURI = RedisURI.builder().
                withHost("139.159.217.216").withPort(6379).withClientName("default")
                .withPassword("111111").build();

        //2.创建连接客户端
        RedisClient redisClient = RedisClient.create(redisURI);
        StatefulRedisConnection<String, String> connect = redisClient.connect();

        //3. 通过connect 创建操作的command
        RedisCommands<String, String> sync = connect.sync();

        //lettuce 开始
        List<String> keys = sync.keys("*");
        System.out.println(keys);

        sync.multi();
        sync.set("k1","v1");
        sync.set("k2","v2");
        sync.exec();

        sync.hset("hash1","field1","value1");

        //lettuce 结束



        //4. 关闭各种资源
        connect.close();
        redisClient.shutdown();

    }
}
